package com.example.casclient2.controller;

import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

/**
 * @author lzz
 * @time 2025/3/13
 * @description
 */
@Controller
public class HomeController {


    /**
     * 公开页面
     */
    @GetMapping("/public")
    public String publicPage() {
        return "public";
    }

    /**
     * 受保护页面
     */
    @GetMapping("/protected")
    public String protectedPage(Model model) {
        Authentication auth = SecurityContextHolder.getContext().getAuthentication();
        model.addAttribute("username", auth.getName());
        return "protected";
    }

    /**
     * 首页 - 重定向到公开页面
     */
    @GetMapping("/")
    public String home() {
        return "redirect:/public";
    }
}
